package app;

import java.io.IOException;
import java.net.Socket;
import java.util.Date;

import util.Constants;

public class Client {
	
	public Client(String server, User user) {
		this.user = user;
		try {
			login = new UserSocketConnection(new Socket(server, Constants.LOGIN_PORT), user);
			login.doLogin();
			chat = new UserSocketConnection(new Socket(server, Constants.CHAT_PORT), user);
		} 
		catch (Exception e) {e.printStackTrace();}
	}
	
	public User getUser() {
		return user;
	}
	
	public void setUser(User u) {
		user = u;
	}
	
	public Date getLoginDate() {
		return login.getConnDate();
	}
	
	public Object loginReceive() throws IOException, ClassNotFoundException {
		return login.receive();
	}
	
	public void loginSend(Object o) throws IOException {
		login.send(o);
	}

	public Object chatReceive() throws IOException, ClassNotFoundException {
		return chat.receive();
	}
	
	public void chatSend(Object o) throws IOException {
		chat.send(o);
	}
	
	private UserSocketConnection login;
	private UserSocketConnection chat;
	private User user;
}
